package gui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import model.Element;
import model.SysClass;
import model.SysPackage;


import visualization.ModelToGraph;

import edu.uci.ics.jung.algorithms.layout.TreeLayout;
import edu.uci.ics.jung.graph.DelegateForest;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import gui.MainWindow;


public class MainWindowTest {
	public static Element root1;
	static MainWindow main; 
	

	public static Element makeInitialModel(){
		SysPackage root = new SysPackage("root");
		SysPackage p1 = new SysPackage("package1");
		SysPackage p2 = new SysPackage("package2");
		SysPackage p3 = new SysPackage("package3");
		SysPackage p4 = new SysPackage("package4");
		SysClass c1 = new SysClass("Class1");
		SysClass c2 = new SysClass("Class2");
		SysClass c3 = new SysClass("Class3");

		root.add(p1);
		root.add(p2);
		root.add(p3);
		root.add(p4);
		root.add(c1);
		root.add(c2);
		root.add(c3);
		/*
		secondLevel_dt = new DelegateTree<Element, Float>();
		secondLevel_dt.addVertex(root);
		secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), root, p1);
		secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), root, p2);
		secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), root, p3);
		secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), root, p4);
		secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), root, c1);
		secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), root, c2);
		secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), root, c3);	
		 */
		SysPackage p5 = new SysPackage("package5");
		SysPackage p6 = new SysPackage("package6");
		SysPackage p7 = new SysPackage("package7");
		SysPackage p8 = new SysPackage("package8");
		SysClass c4 = new SysClass("Class4");
		SysClass c5 = new SysClass("Class5");
		SysClass c6 = new SysClass("Class6");
		SysClass c7 = new SysClass("Class7");

		p1.add(p5);
		//secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), p1, p5);
		p5.add(p6);
		//secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), p5, p6);
		p6.add(c4);
		//secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), p6, c4);
		p2.add(p7);
		//secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), p2, p7);
		p3.add(p8);
		//secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), p3, p8);
		c1.add(c5);
		//secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), c1, c5);
		c4.add(c6);
		//secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), c4, c6);
		c6.add(c7);
		//secondLevel_dt.addChild(secondLevel_dt.getEdgeCount(), c6, c7);
		p5.add(new SysPackage("p9"));
		p5.add(new SysPackage("p10"));
		
		root1=root;
		return root;
	}



	@SuppressWarnings("unchecked")
	public static void tryToMakeAFullyGraph(){
		DelegateForest<Element, Float> df = new DelegateForest<Element, Float>(ModelToGraph.delegateTree_fullGraph(makeInitialModel()));
		main = new MainWindow("Main window");
		//main.r=(SysRoot)root1;
		main.setLocation(400, 200);
		main.setCenterPanel(new VisualizationViewer<Element, Float>(new TreeLayout<Element, Float>(df)));
		main.makeGoodVisual((VisualizationViewer<Element, Float>) main.getCenter());
		main.makeMenuBar((VisualizationViewer<Element, Float>) main.getCenter());
		Container c = main.getContentPane();
		JButton topButton = new JButton("Remake default graph");
		ActionListener l = new ActionListener(){
			@SuppressWarnings("rawtypes")
			public void actionPerformed(ActionEvent e) {
				main.setCenterPanel(new VisualizationViewer<Element, Float>(new TreeLayout<Element, Float>(new DelegateForest(ModelToGraph.delegateTree_fullGraph(root1)))));
				main.makeGoodVisual((VisualizationViewer<Element, Float>) main.getCenter());
				((VisualizationViewer)main.getCenter()).updateUI();
			}
		};
		topButton.addActionListener(l);
		c.add(topButton, BorderLayout.PAGE_START);
		
		main.pack();
		main.setExtendedState(MainWindow.MAXIMIZED_BOTH);
		main.setVisible(true);
	}
	
	public static void main(String[] args) {
		tryToMakeAFullyGraph();
	}

}
